<?php
require_once '../defaultconf.mex';
MYTCONN();
$y = 1;
$List = $GLOBALS['MYT']->db_array("SELECT FraCliNombre AS CliNombre, FraBnfNombre AS BnfNombre FROM facturas
        INNER JOIN facturasextjoins ON FraExtID = FraID
        WHERE FraID = 900021");
$List[$y]['BnfNombre'] .=  'oiji';
    # Trata Nome de Cliente
    /* $CliFirstName = preg_split('/ /',$List[$y]['CliNombre']);
      if(!isset($CliFirstName[1])) {$CliFirstName[1] = '';}
      $CliLastName = preg_split('/ /',$List[$y]['CliApellidos']);
      if(!isset($CliLastName[1])) {$CliLastName[1] = '';} */
      echo 'CLI'.$List[$y]['CliNombre'].'<br>';
      echo 'BNF'.$List[$y]['BnfNombre'].'<br>';

    $CliFirstNameAr = preg_split('/ /', $List[$y]['CliNombre']);
    $tCliNames = count($CliFirstNameAr);
    $CliFirstName[0] = $CliFirstNameAr[0];
    if ($tCliNames < 1) {
        $CliFirstName[1] = '';
    } else {
        $CliFirstName[1] = $CliFirstNameAr[$tCliNames - 1];
    }


    # Trata Nome de Beneficiario
    /* $FirstName = preg_split('/ /',$List[$y]['BnfNombre']);
      if(!isset($FirstName[1])) {$FirstName[1] = '';}
      $LastName = preg_split('/ /',$List[$y]['BnfApellidos']);
      if(!isset($LastName[1])) {$LastName[1] = '';} */
    $FirstNameAr = preg_split('/ /', $List[$y]['BnfNombre']);
    echo $tNames = count($FirstNameAr);
    $FirstName[0] = $FirstNameAr[0];
    if ($tNames < 4) {
        $FirstName[1] = '';
    } else {
        $FirstName[1] = $FirstNameAr[$tNames - 3];
    }
    if ($tNames < 3) {
        $FirstName[2] = '';
    } else {
        $FirstName[2] = $FirstNameAr[$tNames - 2];
    }
    if ($tNames < 1) {
        $FirstName[3] = '';
    } else {
        $FirstName[3] = $FirstNameAr[$tNames - 1];
    }
    if ($List[$y]['cb_TipoCuenta'] == 'C/C') {
        $List[$y]['cb_TipoCuenta'] = 0;
    } elseif ($List[$y]['cb_TipoCuenta'] == 'POUP') {
        $List[$y]['cb_TipoCuenta'] = 0;
    }

	# FIX
/*	$CliFirstName[0] = $List[$y]['CliNombre'];
        $CliFirstName[1] = '';
        $FirstName[0] = $List[$y]['BnfNombre'];
        $FirstName[1] = '';
        $FirstName[2] = '';
        $FirstName[3] = '';*/

    printArray($CliFirstName);
    printArray($FirstName);